package source.home;



import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.EditText;

public class login extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.login);
    }
    public void home_click(View button)
    {
    	String server = "http://smsever4guni.appspot.com/";
    	///////////code : take data from text views///////
    	EditText username = (EditText) findViewById(R.id.lusername);
    	EditText password = (EditText) findViewById(R.id.lpassword);
    	InputStream is = null;
    	String result="";
    	String url = server+"userlogincheck?username="+username.getText()+"&password="+password.getText();
    	try
		{
        HttpClient httpclient = new DefaultHttpClient();
      
        HttpGet HttpGet = new HttpGet(url);
        
        HttpResponse response = httpclient.execute(HttpGet);
        HttpEntity entity = response.getEntity();
        is = entity.getContent();
    	///////////////////trial code/////////////////////////
                BufferedReader reader = new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8);
                StringBuilder sb = new StringBuilder();
                String line = null;
                while ((line = reader.readLine()) != null) 
                {
               	 	sb.append(line + "\n");
                }
                is.close();
         
                result=sb.toString();
            	System.out.println("finalresult"+result);
        //////////////////////////////////////////////////////
            if(result.contains("success"))
            {
            	Intent intent = new Intent();
            	intent.setClass(this,home.class);
            	startActivity(intent);
            }
            else
            {
            	Intent intent = new Intent();
            	intent.setClass(this,login.class);
            	startActivity(intent);
            	username.setText("Error");
            	password.setText("Error");
            }
            	
    	
		
    
    
	}
	
	catch(Exception e)
	{
    Log.e("log_tag", "Error in http connection "+e.toString());
    username.setText("Error");
	password.setText("Error");
	//
   	}

}
}